package com.mj.action;

import lombok.Data;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@ParentPackage("struts-default")
@Namespace("/")
@Data
public class TestAction {
    private String fn;
    @Action("/zhujie")
    public String sil(){
        HttpServletResponse response = ServletActionContext.getResponse();
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        try {
            PrintWriter out = response.getWriter();
            out.print("使用注解模式");
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    @Action(value = "/rcode",results = {@Result(type = "plainText",params = {"charset","utf-8","location","/${fn}.jsp"})})
    public String sco(){
        return "success";
    }
}
